//
//  HLTimeVC.m
//  NewKY
//
//  Created by 罗浩林 on 16/11/14.
//  Copyright © 2016年 Dee. All rights reserved.
//

#import "HLTimeVC.h"
#import "UILabel+CZAddition.h"
#import "UIColor+CZAddition.h"
#import "HLTimeFlowLayout.h"
#import "HLTimeCell.h"
#import "HLReservationViewController.h"
#import <SobotKit/SobotKit.h>


static NSString * CellID = @"CellID";

@interface HLTimeVC ()<UICollectionViewDataSource>

@property (nonatomic,assign) int yuyueNum;

@end

@implementation HLTimeVC{
    
    NSArray * _dataArr;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self getMainNavigation].navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    /*---加载本地数据---*/
    
    NSString * path = [[NSBundle mainBundle]pathForResource:@"yuyue.json" ofType:nil];
    
    NSData * data = [NSData dataWithContentsOfFile:path];
    
    NSArray * arr = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    
    _dataArr = arr;
    
}

#pragma mark - UICollectionViewDataSource

/*---返回组---*/
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 4;
}

/*---返回行---*/
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 8;
}

/*---返回的cell---*/
- ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HLTimeCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellID forIndexPath:indexPath];
    
    NSArray * arr = _dataArr[indexPath.section];
    
    cell.celltext = arr[indexPath.item];
    
    cell.backgroundColor = [UIColor whiteColor];
    
    if ([cell.celltext isEqualToString:@"有号"]) {
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickCell:)];
        
        [cell addGestureRecognizer:tap];
        
    }
    
    return cell;
}

#pragma mark - UI搭建

/*---UI搭建---*/
-(void)setupUI{

    UILabel * label = [UILabel cz_labelWithText:@"放号日期" fontSize:15 color:[UIColor cz_colorWithHex:0x9f9f9f]];
    [self.view addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(50);
    }];
    HLTimeFlowLayout * flowLayout = [[HLTimeFlowLayout alloc]init];
    
    UICollectionView * colView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    colView.dataSource = self;
    
    colView.backgroundColor = [UIColor cz_colorWithHex:0xd6d6d6];
    
    [colView registerClass:[HLTimeCell class] forCellWithReuseIdentifier:CellID];
    
    [self.view addSubview:colView];
    
    [colView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(10);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(230);
    }];
    
    
    /*---就诊申请Btn---*/
    UIButton * consultBtn = [[UIButton alloc]init];
    
    consultBtn.backgroundColor = [UIColor cz_colorWithHex:0x21c6c5];
    [consultBtn setTitle:@"咨询" forState:UIControlStateNormal];
    [consultBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    consultBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    consultBtn.layer.cornerRadius = 3;
    [consultBtn addTarget:self action:@selector(clickapplicantBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:consultBtn];
    
    CGFloat spaceRL = 12;
    CGFloat viewH = 35;
    
    [consultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-19);
        make.left.equalTo(self.view).offset(spaceRL);
        make.right.equalTo(self.view).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
}

/*---点按手势监听事件---*/
-(void)clickCell:(UITapGestureRecognizer *)tap{
    
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Reservation" bundle:nil];
    HLReservationViewController *viewCtl = [storyBoard instantiateViewControllerWithIdentifier:@"123"];
    
    [self.navigationController pushViewController:viewCtl animated:YES];
    
}

-(void)clickapplicantBtn:(UIButton *)sender{
    
    
    //企业编号，必填
    //启动
    ZCLibInitInfo *initInfo = [ZCLibInitInfo new];
    initInfo.enterpriseId = @"c05b888a771c4c4fb9f2bb93f8a42245";
    
    //用户id,用于表示客户,建议填写
    
    //区分注册用户与游客
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSInteger status = [[userDefaults objectForKey:@"USER_STATUS"]intValue];
    
    NSString *userName = status ? [userDefaults objectForKey:@"NOW_USER_PHONE"] : @"Ghost";
    
    
    initInfo.userId = userName;
    initInfo.phone = @"iPhone 6";
    initInfo.nickName = userName;
    initInfo.avatarUrl = status ? @"https://didee.cn/images/avatar.jpg" : nil;
    
    ZCKitInfo *uiinfo = [ZCKitInfo new];
    uiinfo.info = initInfo;
    
    ZCUIChatController *vc = [[ZCUIChatController alloc]initWithInitInfo:uiinfo];
    
    [[self getMainNavigation] pushViewController:vc animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

 @end
